package com.woniu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.AddCourseDTO;
import com.woniu.pojo.Course;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.vo.CoursePublishVO;
import com.woniu.vo.NewCourseVO;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 课程 Mapper 接口
 * </p>
 *
 * @author xiaoruan
 * @since 2023-03-15
 */
public interface CourseMapper extends BaseMapper<Course> {

    @Select("select * from wnxt_course c ,wnxt_course_description d where c.id = d.id and c.id=#{courseId}")
    AddCourseDTO selectCourseDTOById(String courseId);

    @Update("update wnxt_course set status='Normal' where id=#{courseId} and status='Draft'")
    void updateStatus(String courseId);


    CoursePublishVO selectPublishVO(String courseId);

    @Select("select" +
            " c.id,c.title,c.cover,c.buy_count,(select COUNT(*) from wnxt_video v where c.id=v.course_id ) videoCount " +
            "from wnxt_course c where is_deleted=0 and status='Normal' order by update_time desc limit #{newCourseNum}")
    @ResultType(NewCourseVO.class)
    List<NewCourseVO> queryNewCourse(Integer newCourseNum);


    @Select("select" +
            " c.id,c.title,c.cover,c.buy_count,(select COUNT(*) from wnxt_video v where c.id=v.course_id ) videoCount " +
            "from wnxt_course c where is_deleted=0 and status='Normal' order by buy_count desc limit #{hotCourseNum}")
    @ResultType(NewCourseVO.class)
    List<NewCourseVO> queryHotCourse(Integer hotCourseNum);

    IPage<NewCourseVO> listbySubjectId(IPage<NewCourseVO> page,String subjectId);

    @Select("select c.id,c.title,c.buy_count,c.cover,c.price,(select count(*) from wnxt_video v where v.course_id =c.id)  videoCount from wnxt_course c where id=#{courseId} and is_deleted=0 and status='Normal'")
    NewCourseVO queryCourseDetilBycourseId(String courseId);

    @Select("select" +
            " c.id,c.title,c.cover,(select COUNT(*) from wnxt_video v where c.id=v.course_id ) videoCount " +
            "from wnxt_course c where is_deleted=0 and status='Normal' order by buy_count desc limit #{detailCourseNum}")
    @ResultType(NewCourseVO.class)
    List<NewCourseVO> queryDetailCourse(Integer detailCourseNum);

}
